from dbmodels.trait import TraitModel

from protorpc import messages
from protorpc import message_types
from protorpc import remote

package = "api"

class TraitMessage(messages.Message):
    id = messages.StringField(1, required=True)
    name = messages.StringField(2, required=True)
    label = messages.StringField(3, required=False)
    type = messages.StringField(4, required=True)
    effect = messages.StringField(5, required=False)

class TraitService(remote.Service):

    @remote.method(TraitMessage, message_types.VoidMessage)
    def add(self, request):
        trait = TraitModel(
            key_name = request.id,
            name = request.name,
            label = request.label,
            type = request.type,
            effect = request.effect
        )
        trait.put()

        return message_types.VoidMessage()
